package com.water.wfo.user.ability.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.water.wfo.sys.pojo.entity.DataDictionaryEntity;
import com.water.wfo.sys.pojo.entity.RoleEntity;
import com.water.wfo.sys.pojo.request.DataDictionaryRequest;
import com.water.wfo.sys.pojo.response.DataDictionaryResponse;
import com.water.wfo.sys.pojo.response.RoleResponse;
import com.water.wfo.user.ability.DataDictionaryAbility;
import com.water.wfo.user.mapper.DataDictionaryMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 数据字典 服务实现类
 * </p>
 *
 * @author water&7
 * @since 2024-07-24
 */
@Slf4j
@Component
public class DataDictionaryAbilityImpl implements DataDictionaryAbility {

    @Autowired
    private DataDictionaryMapper dataDictionaryMapper;
    @Override
    public void insert(DataDictionaryEntity dictionaryEntity) {
        dataDictionaryMapper.insert(dictionaryEntity);
    }

    @Override
    public int update(DataDictionaryEntity entity) {
        return dataDictionaryMapper.update(entity);
    }

    @Override
    public DataDictionaryResponse queryDataDictEntityBy(DataDictionaryRequest request) {
        List<DataDictionaryEntity> dictionaryEntities = null;
        try {
            PageHelper.startPage(request.getPageNum(),request.getPageSize());
            dictionaryEntities = dataDictionaryMapper.queryDataDictEntityBy(request);
        } catch (Exception e) {
            log.error(e.getMessage());
        } finally {
            PageHelper.clearPage();
        }
        //得到分页的结果对象
        PageInfo<DataDictionaryEntity> personPageInfo = new PageInfo<>(dictionaryEntities);
        //得到分页中条目对象
        List<DataDictionaryEntity> pageList = personPageInfo.getList();
        DataDictionaryResponse response = new DataDictionaryResponse();
        response.setDictionaryEntities(pageList);
        response.setTotal(personPageInfo.getTotal());
        return response;
    }

    @Override
    public int deleteBatchByIds(List<Long> list) {
        if(CollectionUtils.isEmpty(list)){
            return 0;
        }
        return dataDictionaryMapper.deleteBatchByIds(list);
    }
}
